using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using IReaper.WWE;

namespace IReaper.Statues
{
    public partial class OnDemandWork : AsyncWork
    {
        #region instance field
        string eventID = null;
        WWEManager manager;
        #endregion
        #region ctr
        public OnDemandWork(string EventID)
            : this()
        {
            this.eventID = EventID;
            manager = new WWEManager(this.eventID);
            manager.OnDemandProgreesed += new WWEProgressed(manager_OnDemandProgreesed);
        }

        void manager_OnDemandProgreesed(string ProgressName)
        {
            this.Status.TaskMessage = ProgressName;
        }

        public OnDemandWork()
        {
            InitializeComponent();
        }

        public OnDemandWork(IContainer container)
        {
            container.Add(this);

            InitializeComponent();
        }
        #endregion

        protected override void OnDoWork(DoWorkEventArgs e)
        {
            base.OnDoWork(e);
            if (string.IsNullOrEmpty(this.eventID))
                return;
            try
            {
                string videoUrl = this.manager.GeOnDemandUrl();
                System.Diagnostics.Process.Start(videoUrl);
            }
            catch (UnRegisteredException urEx)
            {
                Browser.BrowserManager.OpenWebsiteWithWLI(urEx.RegisterUrl);
                return;
            }
           
        }

    }
}
